/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entity.Ipod;
import entity.Ipodtype;
import java.util.ArrayList;
import org.hibernate.Query;
import org.hibernate.Session;
import util.AppHibernateUtil;

/**
 *
 * @author Turtle
 */
public class IpodTypeDAO {

    public static Ipodtype getTypeByID(String id) {
        Ipodtype type = new Ipodtype();

        Session session = AppHibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();

        String hql = "from Ipodtype where id=:_id";

        Query query = session.createQuery(hql);
        query.setParameter("_id", id);

        ArrayList<Ipodtype> list = (ArrayList<Ipodtype>) query.list();

        if (list.size() > 0) {
            type = (Ipodtype) query.list().get(0);
        }

        return type;
    }
    
    public static ArrayList<Ipodtype> getTypeList() {
        ArrayList<Ipodtype> type = new ArrayList<Ipodtype>();

        Session session = AppHibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();

        String hql = "from Ipodtype";

        Query query = session.createQuery(hql);

        type = (ArrayList<Ipodtype>) query.list();

        return type;
    }
}
